const express = require("express");
const app = new express();  //new可以省掉
const cors = require("cors") //cnpm i cors --save
//引入路由模块
const userRouter = require("./routes/users")

//配置post发送的文本数据
app.use(express.urlencoded({
    extended: false
}))
app.use(express.json())
app.use(cors())  //允许跨域

//后台允许前端跨域请求数据开始
// app.all('*', function (req, res, next) {
//     res.header('Access-Control-Allow-Origin', '*');
//     res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
//     res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');

//     if (req.method == 'OPTIONS') {
//         res.send(200);
//     } else {
//         next();
//     }
// });
//后台允许前端跨域请求数据结束
//应用级中间件
app.use("/api/user", userRouter)


app.listen(3000, () => {
    console.log("3000running");
})